<?php
class Model_User extends Model{
public $table="user"; 
public function insert_user($data){
	if($this->check_user($data[username]) == TRUE){
		$this->insert($this->table,$data);
		return TRUE;
	}else{
		return FALSE;
	}
}
public function check_user($user,$id=""){
	if($id != ""){
		$where=array(
				"username" => "= '$user'",
				"id "	   => "!= '$id'"
		);
	}else{
		$where="username = '$user'";
	}	
	$this->where($where);
	$this->getdata($this->table);
	if($this->num_rows()== 1){
		return FALSE;
	}else{
		return TRUE;
	}
}
public function listuser(){
	$this->order("id DESC");
	$this->getdata($this->table);
	return $this->fetchall();
}
public function delete_user($id){
	$this->where("id = '$id'");
	$this->delete($this->table);
}

public function delete_all($str){
	$this->where("id in ($str)");
	$this->delete($this->table);
}
public function listselect($str){
	$this->select("id, username");
	$this->where("id in ($str)");
	$this->getdata($this->table);
	return $this->fetchall();
}

public function getuser($id){
	$this->where("id = '$id'");
	$this->getdata($this->table);
	return $this->fetchone();
}

public function update_user($data,$id){
	if($this->check_user($data[username],$id) == TRUE){
		$this->where("id = '$id'");
		$this->update($this->table,$data);
		return TRUE;
	}else{
		return FALSE;
	}
}

}